#include "StoryCellWidget.h"

StoryCellWidget::StoryCellWidget(QWidget* parent) : QWidget(parent), ui(new Ui::StoryCellWidgetClass())
{
    ui->setupUi(this);
    setFixedSize(constant.StoryCellSize);
}

StoryCellWidget::~StoryCellWidget()
{
	delete ui;
}

void StoryCellWidget::setUi(const StoryCellData& storyCellData)
{
    this->storyCellData = storyCellData;
}

void StoryCellWidget::mouseReleaseEvent(QMouseEvent* event)
{
    Q_UNUSED(event)
    if (event->button() == Qt::LeftButton)
    {
        emit on_storyCellCell_click(this);
    }
}

void StoryCellWidget::paintEvent(QPaintEvent* event)
{
    QPainter painter(this);

    int w = constant.StoryCellSize.width();
    int h = constant.StoryCellSize.height();

    QRect picRect = QRect(0, 0, w, 250);
    painter.drawPixmap(picRect, storyCellData.picture);

    QRect descRect = QRect(0, 250, w, 80);
    painter.drawText(descRect, storyCellData.description);

    QRect userAvatarRect = QRect(0, 250 + 80, w / 4, h - 250 - 80);
    painter.drawPixmap(userAvatarRect, storyCellData.userAvatar);

    QRect userNameRect = QRect(w / 4, 250 + 80, w - w / 4, h - 250 - 80);
    painter.drawText(userNameRect, storyCellData.description);
}
